// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraExperienceActionSet.h"
#include "GameFeatureAction.h"

#if WITH_EDITOR
#include "Misc/DataValidation.h"
#endif

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraExperienceActionSet)

#define LOCTEXT_NAMESPACE "LyraSystem"

/**
 * 构造函数
 */
ULyraExperienceActionSet::ULyraExperienceActionSet()
{
}

#if WITH_EDITOR
/**
 * 数据验证
 * @param Context 数据验证上下文
 * @return 数据验证结果
 */
EDataValidationResult ULyraExperienceActionSet::IsDataValid(FDataValidationContext& Context) const
{
	EDataValidationResult Result = CombineDataValidationResults(Super::IsDataValid(Context), EDataValidationResult::Valid); // 组合数据验证结果

	int32 EntryIndex = 0; // 条目索引
	// 遍历所有操作
	for (const UGameFeatureAction* Action : Actions)
	{
		// 如果操作有效
		if (Action)
		{
			EDataValidationResult ChildResult = Action->IsDataValid(Context); // 子结果验证
			Result = CombineDataValidationResults(Result, ChildResult); // 组合结果
		}
		else
		{
			Result = EDataValidationResult::Invalid; // 结果无效
			Context.AddError(FText::Format(LOCTEXT("ActionEntryIsNull", "Actions中的索引{0}处有空条目"), FText::AsNumber(EntryIndex))); // 添加错误
		}

		++EntryIndex; // 递增索引
	}

	return Result; // 返回结果
}
#endif

#if WITH_EDITORONLY_DATA
/**
 * 更新资源包数据
 */
void ULyraExperienceActionSet::UpdateAssetBundleData()
{
	Super::UpdateAssetBundleData(); // 调用父类实现

	// 为每个操作添加额外的资源包数据
	for (UGameFeatureAction* Action : Actions)
	{
		if (Action)
		{
			Action->AddAdditionalAssetBundleData(AssetBundleData); // 添加额外资源包数据
		}
	}
}
#endif // WITH_EDITORONLY_DATA

#undef LOCTEXT_NAMESPACE